<%--
  Created by IntelliJ IDEA.
  User: dqf
  Date: 2015/3/2
  Time: 16:18
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://"
            + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
%>

<div class="row">
    <!-- NEW WIDGET START -->
    <article class="col-sm-12 col-md-12 col-lg-12">
        <div class="jarviswidget well" id="wid-id-3"
             data-widget-colorbutton="false"
             data-widget-editbutton="false"
             data-widget-togglebutton="false"
             data-widget-deletebutton="false"
             data-widget-fullscreenbutton="false"
             data-widget-custombutton="false"
             data-widget-sortable="false">
            <!-- widget div-->
            <div>
                <div class="widget-body">
                    <a class="btn btn-default" id="linkman-re-common" href="javascript:void(0)">
                        <i class="fa fa-lg fa-mail-reply-all"></i>返回
                    </a>
                    <s:if test="announce.id!=null">
                        <a class="btn btn-default pull-right pull-right-fix" id="btn-comment" href="javascript:void(0);"><i class="fa fa-lg fa-comment-o"></i> 批注</a>
                    </s:if>
                    <a class="btn btn-default pull-right pull-right-fix" id="btn-save-common" href="javascript:void(0);"><i class="fa fa-lg fa-download"></i> 保存</a>
                    <hr class="simple">
                    <form id="announce" class="smart-form" novalidate="novalidate" action="" method="post">
                        <input type="hidden" name="keyId" id="keyId" value="<s:property value="announce.id" />"/>
                        <header id="title" style="display: block;">
                            公告信息
                        </header>
                        <fieldset>
                            <div class="row">
                                <label class="label col col-2">
                                    <i class="fa fa-asterisk txt-color-red"></i>
                                    发布日期
                                </label>
                                <section class="col col-2">
                                    <label class="input">
                                        <i class="icon-append fa fa-calendar"></i>
                                        <input  class="hasDatepicker form-control" name="publishTime"
                                               type="text" value="<s:date name="announce.publishTime" format="yyyy-MM-dd"/>">
                                    </label>
                                </section>
                            </div>
                            <div class="row">
                                <label class="label col col-2">
                                    <i class="fa fa-asterisk txt-color-red"></i>
                                     主题
                                </label>
                                <section class="col col-5">
                                    <label class="input">
                                        <input type="text" name="theme" id="theme" placeholder="请输入主题" value="<s:property value="announce.name"/>">
                                    </label>
                                </section>
                            </div>
                            <div class="row">
                                <label class="label col col-2">
                                    <i class="fa fa-asterisk txt-color-red"></i>
                                    公告内容
                                </label>
                                <section class="col col-5">
                                    <label class="input">
                                        <input type="text" name="content" id="content" placeholder="请输入公告内容" value="<s:property value="announce.content"/>">
                                    </label>
                                </section>
                            </div>
                            <div class="row">
                                <label class="label col col-2">
                                    <i class="fa fa-asterisk txt-color-red"></i>
                                    通知类型
                                </label>
                                <section class="col col-5">
                                    <div class="inline-group">
                                        <label class="radio">
                                            <input type="radio" id="callall" name="callType" value="all"  <s:property value="announce.callType==0?'checked':''"/>>
                                            <i></i>全员</label>
                                        <label class="radio">
                                            <input type="radio" id="callpart" name="callType" value="part" <s:property value="announce.callType==1?'checked':''"/>>
                                            <i></i>部分人员</label>
                                    </div>
                                </section>
                            </div>
                            <div id="callType_part" class="row" style="display: none;">
                                <label class="label col col-2">
                                    <i class="fa fa-asterisk txt-color-red"></i>
                                    <a  href="javascript:void(0);" key="btn-choose-group"> 通知成员</a>
                                </label>
                                <section class="col col-5">
                                    <label class="input">
                                        <input disabled type="text" id="userName" onfocus="setState();"
                                               value="<s:iterator id="list" value="usersSet"><s:property value="#list.name"/>,</s:iterator>"/>
                                        <input type="hidden" id="userId" name="userId"
                                               value="<s:iterator id="list" value="usersSet"><s:property value="#list.id"/>,</s:iterator>"/>
                                    </label>
                                </section>
                            </div>
                        </fieldset>
                    </form>
                </div>
            </div>
        </div>
    </article>
</div>

<script>
    $(function(){
       $("input[name='callType']:checked").each(function(i,v){
          if($(v).val()=='part'){
              $("#callType_part").show();
          }
       });
    });
    function setState(){
        $("#userName").attr("disabled",true);
    }

    $("input[name='callType']").unbind("click").bind("click",function(){
        var typeValue=$(this).val();
        if($(this).prop("checked") && typeValue=='part'){
            $("#userName").removeAttr("disabled");
            $("#userId").val("");
            $("#userName").val("");
            $("#callType_part").show();
        };
        if($(this).prop("checked") && typeValue=='all')$("#callType_part").hide();
    });

    //返回视图
    $("#linkman-re-common").click(function(){
        loadURL("ajax!announce.action",$('#content'));
    });
    //校验
    $("#announce").validate({
        rules : {
            publishTime : {
                required : true
            },
            theme : {
                required : true
            },
            content : {
                required : true
            }
        },
        messages : {
            publishTime : {
                required : '请输入时间'
            },
            theme : {
                required : '请输入主题'
            },
            content : {
                required : '请选择客户性质'
            }
        },
        ignore: "",
        errorPlacement : function(error, element) {
            error.insertAfter(element.parent());
        }
    });

    $('.hasDatepicker').datetimepicker({
        format: 'yyyy-mm-dd',
        weekStart: 1,
        autoclose: true,
        todayBtn: 'linked',
        language: 'zh-CN',
        minView:2
    });
    //保存
    $("#btn-save-common").click(
            function(e) {
                var $valid = $("#announce").valid();
                if(!$valid) return false;
                $.SmartMessageBox({
                    title : "提示：",
                    content : "确定提交吗？",
                    buttons : '[取消][确认]'
                }, function(ButtonPressed) {
                    if (ButtonPressed === "取消") {
                        e.preventDefault();
                        e.stopPropagation();
                        return;
                    }
                    if (ButtonPressed === "确认") {
                        $("#btn-save-common").attr("disabled", "disabled");
                        form_save("announce","<%=path%>/com/ajax-announce!save.action");
                        loadURL("ajax!announce.action",$('#content'));
                    }
                });
            }
    );
</script>

<script type="text/javascript">
    //选择项目组成员
    $("a[key='btn-choose-group']").unbind("click").bind("click",function(){
        ajax_action("ajax-dialog!usersDlg.action",{keyIds:$("#userId").val()},{},function(pdata){
            oDialog.open({
                title:"请选择项目组成员",
                data:pdata.data.data,
                callback:function(){
                    var obj =$("#group input:checked");
                    var name = getArrProp(obj,"key");
                    var id = getArrProp(obj,"id");
                    $("div.widget-body #userName").val(name);
                    $("div.widget-body #userId").val(id);
                }
            });
        });
    });

    //批注
    $("#btn-comment").off("click").on("click",function(){
        var actionUrl = "ajax-comment!list.action";
        var id = $("form#announce input#keyId").val();
        var data = {keyId:id};
        $(this).leftview('init',{
            title:"批注信息",
            actionUrl:actionUrl,
            data:data
        });
        $(this).leftview('foot',{callback:common_click});

    });
    function common_click(){
        $("#left_foot_btn_comment").off("click").on("click",function(){
            var actionUrl = "ajax-comment!save.action";
            var id = $("form#announce input#keyId").val();
            var text = $("#chat_textarea-expand").val();
            var userId = $("#userId").val();
            var parentId = $("#chat_keyId li:first").attr("id");
            var data = {
                targetId:id,
                parentId:parentId,
                text:text,
                toUsersId:userId,
                targetObject:"com.joint.core.entity.Announce"
            };
            ajax_action(actionUrl,data,null,function(data){
                _show(data);
                $(this).leftview('leftClose');
            });
        })
    }
</script>